<?php
/**
 * Created by PhpStorm.
 * User: HP
 * Date: 2021/6/8
 * Time: 11:33
 */

namespace app\backend\validate;

use think\Validate;
class DynamicValidate extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'title' => 'require|max:50',
        'content' => 'require',
        'type' => 'require|number',
        'keyword' => 'require|max:25',
        'source' => 'require|max:25',
        'edit' => 'require|max:25',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'title.require' => '请输入标题！',
        'title.max' => '标题不能超过50位！',
        'content.require' => '请输入内容！',
        'type.require' => '请输入分类',
        'type.number'  => '分类必须是数字',
        'keyword.require' => '请输入关键字！',
        'keyword.max' => '关键字不能超过25位！',
        'source.require' => '请输入来源！',
        'source.max' => '来源不能超过25位！',
        'edit.require' => '请输入编辑！',
        'edit.max' => '编辑不能超过25位！',
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'create' => ['title','content','type','keyword','source','edit'],
        'update' => ['title','content','type','keyword','source','edit']
    ];
}